import { Controller, Post, Body, HttpCode } from "@nestjs/common";
import { ApiTags, ApiBody, ApiOperation, ApiBearerAuth } from "@nestjs/swagger";
import { CreateFeedbackDto } from "./feedback.dto";
import { FeedbackService } from "./feedback.service";
import { AuthUser } from "../auth/decorators/auth-user.decorator";
import { Public } from "../auth/decorators/public.decorator";
import { BusinessException } from "~/common/exceptions/biz.exception";
import { ErrorEnum } from '~/constants/error-code.constant'

@ApiTags("Feedback - 反馈模块")
@Controller('feedback')
export class FeedbackController {
	constructor(
		private feedbackService: FeedbackService,
	) { }

	@ApiBearerAuth()
	@Post("add")
	@ApiOperation({ summary: '反馈' })
	@ApiBody({ type: CreateFeedbackDto })
	async addFeedback(@AuthUser() user: IAuthUser, @Body() createFeedbackDto: CreateFeedbackDto) {
		if (!user) {
			throw new BusinessException(ErrorEnum.USER_NOT_FOUND)
		}

		return await this.feedbackService.add(createFeedbackDto.content, user.uid)
	}

	@Post("public/add")
	@Public()
	@ApiOperation({ summary: '公共反馈' })
	@ApiBody({ type: CreateFeedbackDto })
	async addPublicFeedback(@Body() createFeedbackDto: CreateFeedbackDto) {
		return await this.feedbackService.addByOne(createFeedbackDto.content)
	}

	// TODO 查询所有反馈信息
}